package top.zuli.package01.class14;

public class WindowTest5 {
    public static void main(String[] args) {
        Runnable runnable = new Window5();
        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        Thread t3 = new Thread(runnable);
        t1.start();
        t2.start();
        t3.start();
    }
}

class Window5 implements  Runnable{
    private int ticket = 100;
    private boolean tag = true;
    @Override
    public void run() {
        while(tag){
            show();
        }
    }
    public synchronized void show(){// 相当于this
        if(ticket>0){
            System.out.println(Thread.currentThread().getName()+"卖票,票号："+ticket);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ticket--;
        } else {
            tag = false;
        }
    }
}
